home *** CD-ROM | disk | FTP | other *** search
- /*
- TransSkel multiple-window demonstration: TextEdit module
-
- This module handles a simple TextEdit window, in which text may be
- typed and standard Cut/Copy/Paste/Clear operations may be performed.
- Undo is not supported, nor is text scrolling.
-
- 14 June 1986 Paul DuBois
- */
-
- # include "MultiSkel.h"
- # include <TextEdit.h>
-
-
- /* edit menu item numbers */
-
- typedef enum {
- undo = 1,
- /* --- */
- cut = 3,
- copy,
- paste,
- clear
- } editItems;
-
-
-
- /*
- Text Window - simple text editing window
- */
-
- WindowPtr editWind;
- static TEHandle teEdit; /* handle to text window TextEdit record */
-
-
- static Halt ()
- {
- TEDispose (teEdit);
- CloseWindow (editWind);
- }
-
-
- static Idle ()
- {
- TEIdle (teEdit); /* blink that cursor! */
- }
-
-
- static Key (ch, mods)
- char ch;
- int mods;
- {
- TEKey (ch, teEdit);
- }
-
-
- static Mouse (thePt, t, mods)
- Point thePt;
- long t;
- int mods;
- {
- TEClick (thePt, (mods & shiftKey) != 0, teEdit);
- }
-
-
- /*
- Update text window. The update event might be in response to a
- window resizing. If so, resize the rects and recalc the linestarts
- of the text. To resize the rects, only the right edge of the
- destRect need be changed (the bottom is not used, and the left and
- top should not be changed). The viewRect should be sized to the
- screen.
- */
-
- static Update (resized)
- Boolean resized;
- {
- Rect r;
-
- r = editWind->portRect;
- EraseRect (&r);
- r.left += 4;
- r.bottom -= 2;
- r.top += 2;
- r.right -= 19;
- if (resized)
- {
- (**teEdit).destRect.right = r.right;
- (**teEdit).viewRect = r;
- TECalText (teEdit);
- }
- DrawGrowBox (editWind);
- TEUpdate (&r, teEdit);
- }
-
-
- static Activate (active)
- Boolean active;
- {
- DrawGrowBox (editWind);
- if (active)
- {
- TEActivate (teEdit);
- DisableItem (editMenu, undo);
- }
- else
- {
- TEDeactivate (teEdit);
- EnableItem (editMenu, undo);
- }
- }
-
-
- /*
- Handle Edit menu items for text window
- */
-
- EditWindEditMenu (item)
- int item;
- {
- switch (item)
- {
- /*
- cut selection, put in TE Scrap, clear clipboard and put
- TE scrap in it
- */
- case cut:
- {
- TECut (teEdit);
- (void) ZeroScrap ();
- (void) TEToScrap ();
- break;
- }
- /*
- copy selection to TE Scrap, clear clipboard and put
- TE scrap in it
- */
- case copy:
- {
- TECopy (teEdit);
- (void) ZeroScrap ();
- (void) TEToScrap ();
- break;
- }
- /*
- get clipboard into TE scrap, put TE scrap into edit record
- */
- case paste:
- {
- (void) TEFromScrap ();
- TEPaste (teEdit);
- break;
- }
- /*
- delete selection without putting into TE scrap or clipboard
- */
- case clear:
- {
- (void) TEDelete (teEdit);
- break;
- }
- }
- }
-
-
- EditWindInit ()
- {
- Rect r;
- StringPtr str;
-
- editWind = GetNewWindow (editWindRes, nil, -1L);
- SkelWindow (editWind, Mouse, Key, Update,
- Activate, nil, Halt, Idle, true);
-
- TextFont (0);
- TextSize (0);
-
- r = editWind->portRect;
- r.left += 4;
- r.bottom -= 2;
- r.top += 2;
- r.right -= 19;
- teEdit = TENew (&r, &r);
- str = (StringPtr) "\pThis is the text editing window.\r";
- TEInsert (&str[1], (long) str[0], teEdit);
- }
-